package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.MenuDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Menu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @创建人 红莲
 * @创建时间 2020/8/31 9:00
 * @版本 1.0
 * @描述
 */
@Service(interfaceClass = MenuService.class)
@Transactional
public class MenuServiceImpl implements MenuService {


   @Autowired
    private MenuDao menuDao;


    public List<Menu> findParent() {
        return menuDao.findParent();
    }

    public PageResult pageQuery(QueryPageBean queryPageBean) {
            Integer currentPage = queryPageBean.getCurrentPage();
            Integer pageSize = queryPageBean.getPageSize();
            String queryString = queryPageBean.getQueryString();
            PageHelper.startPage(currentPage, pageSize);
            Page<Menu> page = menuDao.findByCondition(queryString);
            return new PageResult(page.getTotal(), page.getResult());
    }


    public void add(Menu menu) {
        menuDao.add(menu);
    }

    public List<Menu> findChildren(Integer id) {
        return menuDao.findChildren(id);
    }

    public List<Menu> findAll() {
        return menuDao.findAll();
    }

    public Integer[] findMenuIds(Integer rid) {
        return menuDao.findMenuIds(rid);
    }

    public List<Menu> findMenus() {
        List<Menu> detailMenu = menuDao.findDetailMenu();
        return detailMenu;
    }

    public Menu findById(Integer id) {
        return menuDao.findById(id);
    }

    public void update(Menu menu) {
        menuDao.update(menu);
    }

    public void delete(Integer id) {
        menuDao.delete(id);
    }
}
